import 'dart:io';

import 'package:flutter/material.dart';
import 'package:furaha_mkopo/commonTool/fm_language_tool.dart';
import 'package:furaha_mkopo/page/authentication/dialog/fm_cupertino_image_picker_sheet.dart';
import 'package:furaha_mkopo/page/authentication/dialog/fm_id_card_nida_dialog.dart';
import 'package:furaha_mkopo/page/authentication/dialog/fm_id_card_other_dialog.dart';
import 'package:furaha_mkopo/page/authentication/dialog/fm_id_card_voter_dialog.dart';
import 'package:furaha_mkopo/page/authentication/enum/fm_auth_select_enum.dart';
import 'package:furaha_mkopo/page/authentication/enum/fm_authentication_enum.dart';

abstract class FMIdCardBaseDialog extends StatelessWidget {
  FMAuthenticationEnum type;
  FMAuthSelectEnum select;
  Function(File? value,FMAuthenticationEnum type,FMAuthSelectEnum select,String alighted) onSelect;
  FMIdCardBaseDialog({super.key, required this.type,required this.select, required this.onSelect});

  static void showCardDialog(
      BuildContext context,
      FMAuthenticationEnum type,
      FMAuthSelectEnum select,
      Function(File? value, FMAuthenticationEnum type, FMAuthSelectEnum select,
              String alighted)
          onSelect) {
    if (type == FMAuthenticationEnum.idCardFont) {
      if(select == FMAuthSelectEnum.nida){
        showDialog(context: context, builder: (context){
          return FMIDCardNidaDialog(type: type, select: select, onSelect: onSelect);
        });
      }else if(select == FMAuthSelectEnum.voter){
        showDialog(context: context, builder: (context){
          return FMIDCardVoterDialog(type: type,onSelect: onSelect, select: select,);
        });
      }else {
        showDialog(context: context, builder: (context){
          return FMIDCardOtherDialog(type: type, select: select, onSelect: onSelect);
        });
      }
    }else {
      showDialog(context: context, builder: (context){
        return FMIDCardOtherDialog(type: type,onSelect: onSelect, select: select,);
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: (){
        Navigator.of(context).pop();
      },
      child: Scaffold(
        backgroundColor: Colors.transparent,
        body: GestureDetector(
          onTap: (){

          },
          child: Center(
            child: generatedContent(context),
          ),
        ),
      ),
    );
  }

  Widget generatedContent(BuildContext context);

  String getImagePath(){
    switch(type){
      case FMAuthenticationEnum.idCardFont:
        if(select == FMAuthSelectEnum.nida){
          return FMLanguageTool.getAssets("assets/authentication/ic_id_card_nida_dialog",suffix: ".webp");
        }else if(select == FMAuthSelectEnum.voter){
          return FMLanguageTool.getAssets("assets/authentication/ic_id_card_voter_dialog",suffix: ".webp");
        }else {
          return FMLanguageTool.getAssets("assets/authentication/ic_id_card_font_dialog");
        }
      case FMAuthenticationEnum.idCardBack:
        return 'assets/authentication/ic_id_card_back_dialog.png';
      default:
        return FMLanguageTool.getAssets("assets/authentication/ic_id_card_face_dialog");
    }
  }

  void onNext(BuildContext context){
    String alighted = '';
    if(type == FMAuthenticationEnum.face){
      FMCupertinoImagePickerSheet.showImageSourceTakePhoto(context,imageSource: (imageSource){
        alighted = imageSource;
      }).then((value){
        onSelect(value,type,select,alighted);
        Navigator.of(context).pop();
      });
    }else{
      FMCupertinoImagePickerSheet.showImageSourceSelector(context,imageSource: (imageSource){
        alighted = imageSource;
      }).then((value){
        onSelect(value,type,select,alighted);
        Navigator.of(context).pop();
      });
    }
  }

  Widget generateNextButton(BuildContext context){
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: (){
        onNext(context);
      },
      child: Container(
        margin: const EdgeInsets.only(top: 40, left: 20, right: 20),
        height: 47,
        width: double.infinity,
        alignment: Alignment.center,
        decoration: const BoxDecoration(
          color: Color(0xFF000000),
          borderRadius: BorderRadius.all(Radius.circular(8)),
          image: DecorationImage(
            image: AssetImage('assets/address/ic_address_arrow.png'),
          ),
        ),
        child: Text(
          FMLanguageTool.getText('Next'),
          style: const TextStyle(
            color: Colors.white,
            fontSize: 18,
            fontWeight: FontWeight.w700,
          ),
        ),
      ),
    );
  }

  Widget generateCancelButton(BuildContext context){
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: (){
        Navigator.of(context).pop();
      },
      child: Container(
        margin: const EdgeInsets.only(top: 10),
        alignment: Alignment.center,
        child: Text(
          FMLanguageTool.getText("Cancel"),
          style: const TextStyle(
            color: Color(0xFF333333),
            fontSize: 16,
          ),
        ),
      ),
    );
  }
}
